package com.zzyl.nursing.controller;

import java.util.List;

import com.zzyl.nursing.dto.DeviceDTO;
import com.zzyl.nursing.dto.DeviceDetailsDTO;
import com.zzyl.nursing.dto.QueryThingModelPublishedDTO;
import com.zzyl.nursing.vo.ProjectVO;
import com.zzyl.nursing.vo.QueryThingModelPublishedVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author 张三
 * @date 2025-07-05
 */
@Api(tags = "设备管理")
@RestController
@RequestMapping("/nursing/device")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;


    @PostMapping("/queryThingModelPublication")
    public AjaxResult queryThingModelPublished(@RequestBody QueryThingModelPublishedDTO dto){
        QueryThingModelPublishedVO vo = deviceService.queryThingModelPublished(dto);
        return AjaxResult.success(vo);

    }

    @PostMapping("/queryDeviceDetail")
    public AjaxResult queryDeviceDetail(@RequestBody DeviceDetailsDTO dto){
        return AjaxResult.success(deviceService.queryDeviceDetail(dto));
    }



    @PostMapping("/register")
    public AjaxResult registerDevice(@RequestBody DeviceDTO dto){
        deviceService.registerDevice(dto);
        return AjaxResult.success();
    }


    /// /////////////////1.1 从物联网平台同步产品列表/////////////////////
    @GetMapping("/allProduct")
    public AjaxResult getAllProduct(){
        List<ProjectVO> vos = deviceService.getAllProduct();
        return AjaxResult.success(vos);
    }

    /// /////////////////1.1 从物联网平台同步产品列表/////////////////////


    /// /////////////////1.1 从物联网平台同步产品列表/////////////////////
    @PostMapping("/syncProductList")
    public AjaxResult syncProductListFromIot(){
        deviceService.syncProductListFromIot();
        return AjaxResult.success();
    }

    /// /////////////////1.1 从物联网平台同步产品列表/////////////////////

    /**
     * 查询设备列表
     */
    @ApiOperation("查询设备列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Device>> list(@ApiParam("设备查询条件") Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }
}
